# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=cssselect
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-${_realname}" "${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=1.0.3
pkgrel=1
arch=('any')
license=('BSD')
url="https://pypi.python.org/pypi/cssselect"
makedepends=("${MINGW_PACKAGE_PREFIX}-python2"
             "${MINGW_PACKAGE_PREFIX}-python3"
             "${MINGW_PACKAGE_PREFIX}-python2-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python3-setuptools")
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/scrapy/cssselect/archive/v${pkgver}.tar.gz")
sha256sums=('203d9691c42c13cffe26a2f8fc714977882fcf54a6df82c8eda3371f6beaecdb')

prepare() {
  cd "${srcdir}"
  sed -e "s|# coding: utf8|# -*- encoding:utf-8 -*-|g" -i ${_realname}-${pkgver}/setup.py
  for builddir in python{2,3}-build-${CARCH}; do
    rm -rf ${builddir} | true
    cp -r "${_realname}-${pkgver}" "${builddir}"
  done
}

build() {
  for pver in {2,3}; do  
    msg "Python ${pver} build for ${CARCH}"  
    cd "${srcdir}/python${pver}-build-${CARCH}"
    ${MINGW_PREFIX}/bin/python${pver} setup.py build
  done
}

package_python2-cssselect() {
  pkgdesc="A Python2 library that parses CSS3 Selectors and translates them to XPath 1.0 (mingw-w64)"
  depends=("${MINGW_PACKAGE_PREFIX}-python2>")

  cd "${srcdir}/python2-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=;--install-purelib=;--install-data=" \
    ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}" --optimize=1
  install -D -m644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python2-${_realname}/LICENSE"
}

package_python3-cssselect() {
  pkgdesc="A Python3 library that parses CSS3 Selectors and translates them to XPath 1.0 (mingw-w64)"
  depends=("${MINGW_PACKAGE_PREFIX}-python3")

  cd "${srcdir}/python3-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=;--install-purelib=;--install-data=" \
    ${MINGW_PREFIX}/bin/python3 setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}" --optimize=1
  install -D -m644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python3-${_realname}/LICENSE"
}

package_mingw-w64-i686-python2-cssselect() {
  package_python2-cssselect
}

package_mingw-w64-i686-python3-cssselect() {
  package_python3-cssselect
}

package_mingw-w64-x86_64-python2-cssselect() {
  package_python2-cssselect
}

package_mingw-w64-x86_64-python3-cssselect() {
  package_python3-cssselect
}
